<template>
  <div class="hz-header">
    <div class="header-top">
      <div class="logo"></div>
      <h4 class="top-name">{{ $t('company') }}</h4>
      <div class="top-right">
        <a class="fast-nav line-l pc-only" href="/#/homepage">{{ $t('navbar.home') }}</a><a class="fast-nav pc-only" href="/#/contact-us">{{ $t('navbar.contact') }}</a>
        <a class="zh line-l" @click="changeZh()">中文</a><a class="en" @click="changeEn()">EN</a>
      </div>
    </div>
    <slot></slot>
    <div class="header-container">
      <ul class="nav" v-if="isRouter" @click="isShowNavM = false">
        <router-link to='/homepage'>
          <li :class="{active: currentPage('homepage')}"><a href="javascript:void(0);">{{ $t('navbar.home') }}</a></li><!-- &#12288; -->
        </router-link>
        <router-link to='/company-profile'>
          <li :class="{active: currentPage('company-profile')}"><a href="javascript:void(0);">{{ $t('navbar.introduction') }}</a></li>
        </router-link>
        <!-- <li :class="{active: currentPage('product-center')}" @click.stop="isShowNavM = true">
          <router-link to='/product-center/1'><a href="javascript:void(0);">{{ $t('navbar.product') }}</a></router-link>
          <ul class="son-nav pc-only">->
            <li class="levelGauge"><a href="javascript:void(0);">{{ $t('navbar.levelGauge') }}</a><i class="arrow"></i>
              <ul class="three-nav">
                <li><router-link to='/product-center/1'>{{ $t('productList[0]') }}</router-link></li>
                <li><router-link to='/product-center/2'>{{ $t('productList[1]') }}</router-link></li>
              </ul>
            </li>
            <li><router-link to='/product-center/3'>{{ $t('productList[2]') }}</router-link></li>
            <li><router-link to='/product-center/4'>{{ $t('productList[3]') }}</router-link></li>
            <li><router-link to='/product-center/5'>{{ $t('productList[4]') }}</router-link></li>
          </ul>
        </li> -->
        <li :class="{active: currentPage('product-center')}" @click.stop="isShowNavM = true">
          <router-link :to="Rlink(productList[0])">{{ $t('navbar.product') }}</router-link>
          <ul class="son-nav pc-only">
            <!-- <li class="levelGauge"><a href="javascript:void(0);">{{ $t('navbar.levelGauge') }}</a><i class="arrow"></i>
              <ul class="three-nav">
                <li><router-link to='/product-center/1'>{{ $t('productList[0]') }}</router-link></li>
                <li><router-link to='/product-center/2'>{{ $t('productList[1]') }}</router-link></li>
              </ul>
            </li> -->
            <li v-for="(item, index) in productList" class="levelGauge"><router-link :to="Rlink(item)">{{ item.cate_name }}</router-link>
              <i class="arrow" v-if="item.list"></i>
              <ul class="three-nav" v-if="item.list">
                <li v-for="(item2, index2) in item.list"><router-link :to="'/product-center/'+item2.cate_id">{{ item2.cate_name }}</router-link></li>
              </ul>
            </li>
          </ul>
        </li>
        <router-link to='/news-dynamic'>
          <li :class="{active: currentPage('news-dynamic')}"><a href="javascript:void(0);">{{ $t('navbar.news') }}</a></li>
        </router-link>
        <router-link to='/service'>
          <li :class="{active: currentPage('service')}"><a href="javascript:void(0);">{{ $t('navbar.service') }}</a></li> <!--  -->
        </router-link>
        <router-link to='/contact-us'>
          <li :class="{active: currentPage('contact-us')}"><a href="javascript:void(0);">{{ $t('navbar.contact') }}</a></li>
        </router-link>
        <router-link to='/message-board'>
          <li :class="{active: currentPage('message-board')}"><a href="javascript:void(0);">{{ $t('navbar.message') }}</a></li>
        </router-link>
      </ul>
    </div>
    <ul class="son-nav-m phone-only" v-show="isShowNavM">
      <li :class="{active2: currentPage('product-center/' + item.cate_id)}" v-for="(item, index) in productList"><router-link :to="Rlink(item)">{{ item.cate_name }}</router-link></li>
    </ul>
  </div>
</template>

<script>
  export default {
    name: 'hz-header',
    props: {
      isRouter: {
        type: Boolean,
        default: true,
      }
    },
    data() {
      return {
        isShowNavM: false,
        productList: []
      }
    },
    mounted() {
      this.getNavList();
    },
    methods: {
      Rlink(item) {
        if (item.cate_id) {
          return '/product-center/' + item.cate_id
        } else {
          return '/product-center/' + item.list[0].cate_id
        }
      },
      currentPage(index) {
        return -1<this.$route.path.indexOf(index) || -1<location.href.indexOf(index);
      },
      changeZh() {
        this.$i18n.locale = 'zh'
      },
      changeEn() {
        this.$i18n.locale = 'en'
      },
      getNavList() {
        let that = this;
        if (window.DEBUGGING) {
          return new Promise((resolve) => {
            resolve([{
              cate_name: '物位计',
              list: [{
                cate_name: '雷达物位计',
                cate_id: 1
              },{
                cate_name: 'BIOEA超声波液位计',
                cate_id: 2
              }]
            },{
              cate_name: 'BIOEA超声波液位计',
              cate_id: 3
            },{
              cate_name: '流量计',
              cate_id: 4
            },{
              cate_name: '二次仪表',
              cate_id: 5
            }])
          }).then((res) => {
            that.productList = res;
          })
        }

        this.$axios.get('/pc.php/goods/goodsCateList').then((res) => {
          that.productList = res.data
        })
      }
    }
  }
</script>

<style lang="less">
  @import '~COMMON/common.less';

  .hz-header {
    // text-align: center;
    .header-top {
      width: 100%;
      height: 108px;
      box-sizing: border-box;
      padding-left: 80px;
      padding-right: 100px;
      background-color: #fff;
      line-height: 108px;
      .On-xs({
        padding-left: 15px;
        padding-right: 20px;
        height: 53px;
        line-height: 53px;
      });
      .logo {
        display: inline-block;
        vertical-align: middle;
        width: 72px;
        height: 68px;        
        margin-right: 10px;
        background-image: url(~IMGS/logo.jpg);
        background-size: cover;
        .On-xs({
          width: 35px;
          height: 30px;
          margin-right: 0px;
        });
      }
      .top-name {
        display: inline-block;
        vertical-align: middle;
        font-size: 20px;
        color: #006c60;
        .On-xs({
          font-size: 12px;
        });
      }
      .top-right {
        float: right;
        .line-l {
          border-right: 1px solid #e5e5e5;
        }
        >a {
          cursor: pointer;
          font-size: 14px;
          padding: 0 15px;
          color: #666;
          &:hover {
            color: #006c60;
          }
          .On-xs({
            padding: 0 10px;
          });
        }
      }
    }
    .header-container {
      width: 100%;
      text-align: left;
      box-sizing: border-box;
      padding-left: 54px;
      background-color: #339186;
      .On-xs({
        padding-left: 0px;
        width: 100%;
        height: 50px;
        overflow: scroll;
      });
      .nav {
        display: table;
        margin: 0 auto;
        width: 100%;
        .On-xs({
          width: 630px;
        });
        >a, >li {
          display: inline-block;
          min-width: 120px;
          margin-right: 20px;
          text-align: center;
          a {
            line-height: 48px;
            color: #fff;
          }
          .On-xs({
            margin-right: 0px;
            min-width: 90px;
            a {
              color: #333;
              line-height: 50px;
            }
          });
          &:hover {
            background-color: #006d60;
            .On-xs({
              color: #fff;
              background-color: rgba(0,0,0,0);
            });
          }
        }
        li {
          &.active {
            background-color: #006d60;
            .On-xs({
              a{color: #fff;}
              background-color: rgba(0,0,0,0);
            });
          }
        }
        // 有二级导航栏时
        >li {
          min-width: 120px;
          position: relative;
          &:hover {
            .son-nav {
              >li {
                display: block;
              }
            }
          }
          // 二级菜单
          .son-nav {
            position: absolute;
            top: 48px;
            bottom: 0px;
            // width: 150px;
            z-index: 999;
            >li {
              line-height: 40px;
              font-size: 14px;
              display: none;
              background-color: rgba(0,0,0,0.6);
              &:hover {
                background-color: rgba(0,0,0,0.8);
              }
            }
            // 三级菜单...
            .levelGauge {
              width: 120px;
              position: relative;
              &:hover {
                .three-nav {display: block;}
              }
              >a {
                display: inline-block;
                vertical-align: middle;
                // margin-right: 15px;
              }
              .arrow {
                display: inline-block;
                vertical-align: middle;
                width: 12px;
                height: 16px;
                background-image: url(~IMGS/right-arrow.png);
                background-size: cover;
              }
              .three-nav {
                font-size: 12px;
                display: none;
                position: absolute;
                top: 0;
                left: 100%;
                >li {
                  width: 120px;
                  line-height: 40px;
                  background-color: rgba(0,0,0,0.6);
                  &:hover {
                    background-color: rgba(0,0,0,0.8);
                  }
                }
              }
            }
          }
        }
      }
    }
    .son-nav-m {
      font-size: 15px;
      background-color: #fff;
      padding-left: 30px;
      border-bottom: 7px solid #f0f0f0;
      >li {
        position: relative;
        display: inline-block;
        margin: 10px 25px 10px 0;
        line-height: 36px;
        >a {color: #666;}
        &.active2 {
          >a {color: #006d60;}
          &::after {
            content: '';
            position: absolute;
            bottom: 0px;
            left: 50%;
            transform: translateX(-50%);
            display: inline-block;
            width: 40px;
            height: 2px;
            background-color: #006c60;
          }
        }
      }
    }
  }
</style>